package com.qfedu.mtl.controller;

import com.alibaba.fastjson.JSON;
import com.qfedu.mtl.dto.SystemparamDto;
import com.qfedu.mtl.entity.Systemparam;
import com.qfedu.mtl.query.SystemparamQuery;
import com.qfedu.mtl.service.SystemparamService;
import com.qfedu.mtl.service.impl.SystemparamServiceImpl;
import com.qfedu.mtl.util.CharacterUtil;
import com.qfedu.mtl.util.HttpUtil;
import com.qfedu.mtl.util.StrUtil;
import com.qfedu.mtl.util.page.Pager;
import com.qfedu.mtl.util.web.annotation.Controller;
import com.qfedu.mtl.util.web.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @version v1.0
 * @Author NVSonar
 * @Date 2023/9/27 11:40
 * @Email 1595220980@qq.com
 */
@Controller
@RequestMapping("/systemparam")
public class SystemparamController {
	SystemparamService systemparamService=new SystemparamServiceImpl();
	@RequestMapping("/list")
	public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {
		//设置编码
		CharacterUtil.setContentWithJson(request, response);

		String page = StrUtil.ifNull(request.getParameter("page"), "1");
		String size = StrUtil.ifNull(request.getParameter("size"), "10");

		SystemparamQuery systemparamQuery = HttpUtil.request2Bean(request, SystemparamQuery.class);
		Pager<Systemparam> pager = systemparamService.findPage(Integer.valueOf(page), Integer.valueOf(size), systemparamQuery);

		String s = JSON.toJSONString(pager);
		response.getWriter().println(s);

	}

	@RequestMapping("/update")
	public void update(HttpServletRequest request, HttpServletResponse response) throws IOException{
		//设置编码
		CharacterUtil.setContentWithJson(request, response);

		SystemparamDto systemparamDto = HttpUtil.request2Bean(request, SystemparamDto.class);
		systemparamService.update(systemparamDto);

	}

}
